﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Eniux.Windows.ThreeDEngine.Base.CameraControllers;
using System.Windows.Input;
using System.Windows.Media.Media3D;
using Eniux.Windows.ThreeDEngine.Helper;

namespace Eniux.Windows.ThreeDEngine.Base
{
    partial class EniuxViewport3D
    {
        #region 私有变量

        #endregion

        #region 注册依赖属性

        #region ResetCameraGesture（重置相机操作手势）
        /// <summary>
        ///  重置相机操作手势属性
        /// </summary>
        public static readonly DependencyProperty ResetCameraGestureProperty =
            DependencyProperty.Register(
                "ResetCameraGesture",
                typeof(InputGesture),
                typeof(EniuxViewport3D),
                new UIPropertyMetadata(new MouseGesture(MouseAction.MiddleDoubleClick)));

        /// <summary>
        /// 获取或设置重置相机手势
        /// </summary>
        public InputGesture ResetCameraGesture
        {
            get { return (InputGesture)GetValue(ResetCameraGestureProperty); }
            set { SetValue(ResetCameraGestureProperty, value); }
        }
        #endregion

        #region ResetCameraKeyGesture（ 重置相机键盘操作手势属性）
        /// <summary>
        ///   重置相机键盘操作手势属性
        /// </summary>
        public static readonly DependencyProperty ResetCameraKeyGestureProperty =
            DependencyProperty.Register(
                "ResetCameraKeyGesture",
                typeof(KeyGesture),
                typeof(EniuxViewport3D),
                new FrameworkPropertyMetadata(
                    new KeyGesture(Key.Home), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        /// <summary>
        /// 获取或设置重置相机键盘手势
        /// </summary>
        public KeyGesture ResetCameraKeyGesture
        {
            get { return (KeyGesture)GetValue(ResetCameraKeyGestureProperty); }
            set { SetValue(ResetCameraKeyGestureProperty, value); }
        }
        #endregion

        #region ShowCameraInfo（是否显示相机信息）
        /// <summary>
        ///  是否显示相机信息属性
        /// </summary>
        public static readonly DependencyProperty ShowCameraInfoProperty = DependencyProperty.Register(
            "ShowCameraInfo",
            typeof(bool),
            typeof(EniuxViewport3D),
            new UIPropertyMetadata(false, ShowCameraInfoChanged));

        /// <summary>
        /// 获取或设置是否相机信息
        /// </summary>
        public bool ShowCameraInfo
        {
            get { return (bool)GetValue(ShowCameraInfoProperty); }
            set { SetValue(ShowCameraInfoProperty, value); }
        } 
        #endregion

        #region CameraInfo（相机信息）
        /// <summary>
        ///   相机信息属性
        /// </summary>
        public static readonly DependencyProperty CameraInfoProperty = DependencyProperty.Register(
            "CameraInfo", typeof(string), typeof(EniuxViewport3D), new UIPropertyMetadata(null));

        /// <summary>
        /// 获取或设置相机信息
        /// </summary>
        public string CameraInfo
        {
            get { return (string)GetValue(CameraInfoProperty); }
            set { SetValue(CameraInfoProperty, value); }
        }
        #endregion

        #region CameraChanged（相机改变事件）
        /// <summary>
        ///  相机改变事件
        /// </summary>
        public static readonly RoutedEvent CameraChangedEvent = EventManager.RegisterRoutedEvent(
            "CameraChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(EniuxViewport3D));

        /// <summary>
        ///  添加或移除相机改变事件
        /// </summary>
        public event RoutedEventHandler CameraChanged
        {
            add { AddHandler(CameraChangedEvent, value); }
            remove { RemoveHandler(CameraChangedEvent, value); }
        } 
        #endregion

        #endregion


        #region 公共方法
        /// <summary>
        /// 改变相机的观察点
        /// </summary>
        /// <param name="p"></param>
        public void LookAt(Point3D p)
        {
            LookAt(p, 0);
        }

        /// <summary>
        /// 改变相机的观察点
        /// </summary>
        /// <param name="p"></param>
        /// <param name="animationTime"></param>
        public void LookAt(Point3D p, double animationTime)
        {
            CameraHelper.LookAt(Camera, p, animationTime);
        }

        /// <summary>
        /// 改变相机的观察点
        /// </summary>
        /// <param name="p"></param>
        /// <param name="distance"></param>
        /// <param name="animationTime"></param>
        public void LookAt(Point3D p, double distance, double animationTime)
        {
            CameraHelper.LookAt(Camera, p, distance, animationTime);
        }

        /// <summary>
        /// 改变相机的观察点
        /// </summary>
        /// <param name="p"></param>
        /// <param name="direction"></param>
        /// <param name="animationTime"></param>
        public void LookAt(Point3D p, Vector3D direction, double animationTime)
        {
            CameraHelper.LookAt(Camera, p, direction, animationTime);
        }
        #endregion
    }
}
